<!--
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/3/4-16:56
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------
*-->
{extend name='public/base' /}

{block name="css"}
<link href="__PLUGS__/layui/lay/hhymodel/openTable/openTable.css?v=1.0" rel="stylesheet">

{/block}

{block name="content"}

<div class="layui-col-md12">

    <div class="layui-card">
        <div class="layui-card-body layui-row ">


            <!--搜索开始-->
            <form class="layui-form layui-form-pane search-form" method="get">

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">微信昵称</label>
                    <div class="layui-input-inline">
                        <input name="nickname" value="{$Think.get.nickname|default=''}" placeholder="请输入微信昵称" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">关注状态</label>
                    <div class="layui-input-inline">
                        <select class="layui-select" name="subscribe">
                            {foreach ['2'=>'-- 全部 --','0'=>'显示未关注的粉丝','1'=>'显示已关注的粉丝'] as $k=>$v}
                            {eq name='Think.get.subscribe' value='$k.""'}
                            <option selected value="{$k}">{$v}</option>
                            {else}
                            <option value="{$k}">{$v}</option>
                            {/eq}
                            {/foreach}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">拉黑状态</label>
                    <div class="layui-input-inline">
                        <select class="layui-select" name="is_black">
                            {foreach ['2'=>'-- 全部 --','0'=>'显示未拉黑的粉丝','1'=>'显示已拉黑的粉丝'] as $k=>$v}
                            {eq name='Think.get.is_black' value='$k.""'}
                            <option selected value="{$k}">{$v}</option>
                            {else}
                            <option value="{$k}">{$v}</option>
                            {/eq}
                            {/foreach}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">关注时间</label>
                    <div class="layui-input-inline">
                        <input name="subscribe_at" value="{$Think.get.subscribe_at|default=''}" id="test6" placeholder="请选择关注时间" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item ">
                    <button class="layui-btn icon-btn layui-btn-sm" lay-filter="search" lay-submit="">
                        <i class="layui-icon"></i>搜索
                    </button>
                    <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" onclick="javascript:window.location.reload();">
                        <i class="layui-icon layui-icon-refresh"></i> 重置
                    </button>
                </div>
            </form>

        </div>

    </div>

    <div class="layui-card">
        <div class="layui-card-header" style="line-height: 55px;">
            <div class="layui-btn-container do_btn">
                <!--按钮区-->
                <button class="layui-btn layui-btn-sm" data-type="black"><i class="layui-icon"></i>批量拉黑</button>
                <button class="layui-btn layui-btn-sm layui-btn-warm" data-type="bai"><i class="layui-icon layui-icon-fire"></i>取消拉黑</button>
                <button class="layui-btn layui-btn-sm layui-btn-primary" data-type="reload"><i class="fa fa-refresh"></i> 同步粉丝</button>

            </div>
        </div>
        <div class="layui-card-body">

            <!--表格区-->

            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <section class="yys-body">
                            <div class="yys-body-content clearfix changepwd">
                                <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                    <div class="user-tables">
                                        <table id="tableFilter" lay-filter="tableFilter"> </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>

        </div>
    </div>

</div>

{/block}

{block name="js"} <!--js处理区-->
<script type="text/html" id="subscribe">
    {{# if(d.subscribe==0){ }}
    <span class="layui-badge layui-bg-red ">未关注</span>
    {{# }else{ }}
    <span class="layui-badge layui-bg-blue">已关注</span>
    {{# } }}

</script>

<script type="text/html" id="is_black">
    {{# if(d.is_black==1){ }}
    <span class="layui-badge layui-bg-black ">已拉黑</span>
    {{# }else{ }}
    <span class="layui-badge layui-bg-blue">未拉黑</span>
    {{# } }}
</script>

<!--模板-->
<script type="text/html" id="operationTpl">
    {{# if(d.is_black==1){ }}
    <a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-xs " onmouseover="tis(this)" data-title="拉白粉丝" lay-event="bai"><i class="layui-icon layui-icon-ok"></i></a>
    {{# }else{ }}
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs " onmouseover="tis(this)" data-title="拉黑粉丝" lay-event="black"><i class="layui-icon layui-icon-circle-dot"></i></a>
    {{# } }}
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs " onmouseover="tis(this)" data-title="删除粉丝" lay-event="del"><i class="layui-icon "></i></a>
</script>


<script>
    layui.use(['element', 'table', 'form', 'jquery', "laydate",'lucky','util',"openTable"], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        let util=layui.util;
        var openTable=layui.openTable;
        var laydate = layui.laydate;


        //日期范围
        laydate.render({
            elem: '#test6'
            ,range: "|"
        });
        form.render();

        // layer.load(2);
        openTable.render({
            elem: '#tableFilter',
            url:"{:url('fans/index')}",
            //toolbar: '#toolbarDemo',
            // even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:30
                ,limits:[20,30,50,60]
            },
            // height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                {field: 'headimgurl', title: '头像', style:'cursor: pointer;',width: 80, align: "center",templet:function (d) {
                        return '<img src="'+d.headimgurl+'"  layer-index="0" alt="无图" class="layui-nav-img" />';
                    }},
                {field: 'nickname', width: 120, title: '微信昵称'},
                {field: 'openid', width: 300, title: 'openID',templet:function (d) {
                        return '<a data-clipboard-text="'+d.openid+'" class="copy layui-btn layui-bg-gray" title="点击复制" style="top:0;right:0;background:none!important"><i class="fa fa-copy"></i></a><font  onmouseover="tis(this)"  data-title="'+d.openid+'">'+d.openid+'</font>';
                    }},
                {field: 'country',style:'cursor: pointer;',title: '地区',width:150,templet:function (d) {
                       return d.country+d.province+d.city ;
                    }},
                {field:'subscribe',title:'是否关注',templet: '#subscribe',width:90 ,unresize: true},
                {field:'is_black',title:'是否拉黑',templet: '#is_black',width:90 ,unresize: true},
                {field:'sex',title:'性别',width:70 ,unresize: true,templet:function (d) {
                        if (d.sex==1){
                            s='<span class="layui-badge layui-bg-blue">男</span>';
                        } else if(d.sex==2){
                            s='<span class="layui-badge layui-bg-red">女</span>';
                        }else {
                            s='<span class="layui-badge layui-bg-black">未知</span>';
                        }
                        return s;
                    }},
                {field: 'subscribe_time', title: '关注时间',align: 'center',width:160,sort:true,templet:function (d) {
                        return lucky.TimeToTime(d.subscribe_time);
                    }},
                {fixed: 'right',templet: '#operationTpl', width: 160, align: 'center', title: '操作'}
            ]],
            //注：展开的列Items
            openCols: [
                //  1、普通文本
                {field: 'language', title: '语言'},
                {field: 'remark', title: '备注'},
                {field: 'subscribe_scene', title: '扫码关注场景'},
                {field: 'qr_scene', title: '二维码场景值'},
                {field: 'qr_scene_str', title: '场景内容'},
            ]
            //注：监听排序 {openTable}
            ,sort: function (obj) {
                console.log(obj)
            }
            //注：监听修改 {openTable}
            ,edit: function (obj) {
                //layer.msg("修改内容已打印在控制台");
                console.log(obj)
                // 发起 ajax
                // layui.table.reload('#test');
            }

            //注：0：同时只展开一项 1：一直展开不关闭之前  def：0 {openTable}
            , openType: 0
            ,done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch("table_id",obj.field); //查询
            return false;
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            // console.log(JSON.stringify(data));
            var _id=parseInt(data.id);
            let open_id=data.openid;
            var layEvent = obj.event;
            if(layEvent==="black"){
                lucky.FormatData(open_id,"{:url('fans/setBlack')}","table_id","确定拉黑该粉丝？");
            }else if(layEvent==="del"){
                lucky.FormatData(_id,"{:url('fans/remove')}","table_id");
            }else if (layEvent==="bai"){
                lucky.Delete_data(open_id,"{:url('fans/delBlack')}","table_id","确定拉白该粉丝？");
            }
        });


        var active = {
            black:function(){
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].openid);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.FormatData(id,"{:url('fans/setBlack')}","table_id","确定拉黑选择的粉丝？");
            },
            bai: function(){ //获取选中数据
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].openid);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.FormatData(id,"{:url('fans/delBlack')}","table_id","确定取消拉黑选择的粉丝？");
            },
            reload: function(){
                lucky.FormatData(1,"{:url('fans/sync')}","table_id","确定同步粉丝数据？");
            }

        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >


{/block}
